package com.syaccp.controller;


import com.github.pagehelper.PageInfo;
import com.syaccp.model.SysDictData;
import com.syaccp.model.SysDictType;
import com.syaccp.request.DictDataDto;
import com.syaccp.response.DictResponse;
import com.syaccp.service.DictDataService;
import com.syaccp.service.DictTypeService;
import com.syaccp.utils.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author lixin
 * @since 2023-07-02
 */

@RestController
@RequestMapping("/api/dictData")
public class DictDataController {


    @Resource
    private DictDataService dictDataService;


    @GetMapping(value = "/selectDictByType/{type}")
    @ApiOperation(value = "通过类型查询字典表数据")
    @ApiImplicitParam(name = "type",value = "查询的字典类型",required = true)
    public Result selectDictByType(@PathVariable String type){
        System.out.println("type = " + type);
        List<SysDictData> list = dictDataService.selectByType(type);
        List<DictResponse> list1=new ArrayList<>();
        for (SysDictData sysDictData : list) {
            DictResponse dr=new DictResponse();
            BeanUtils.copyProperties(sysDictData,dr);
            list1.add(dr);
        }
        System.out.println(list1);
        return Result.success(list1);
    }

    @ApiOperation(value = "字典表查询风格")
    @GetMapping(value = "/queryDictDataStyleInfo")
    public Result<List<SysDictData>> queryDictDataStyleInfo(){
        return Result.success(dictDataService.queryStyleInfo());
    }

    @Resource
    private DictTypeService dictTypeService;

    /**
     * 查询
     * @param
     * @return
     */
    @ApiOperation("根据状态查询详情")
    @GetMapping("list")
    public Result<PageInfo<SysDictData>> detail(@ApiParam(value = "查询的条件") DictDataDto dictDataDto){
        PageInfo<SysDictData> pageInfo = dictDataService.queryPage(dictDataDto);
        return Result.success(pageInfo);
    }

    /**
     * 新增
     * @param sysDictData
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody SysDictData sysDictData){
        sysDictData.setCreateTime(new Date());
        dictDataService.save(sysDictData);
        return Result.success();
    }

    /**
     * 修改
     * @param sysDictData
     * @return
     */
    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody SysDictData sysDictData){
        sysDictData.setUpdateTime(new Date());
        dictDataService.updateById(sysDictData);
        return Result.success();
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation("根据id查询")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable Long id){
        SysDictData byId = dictDataService.getById(id);
        return Result.success(byId);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Long id){
        dictDataService.removeById(id);
        return Result.success();
    }

    @ApiOperation("查询所有角色")
    @GetMapping("/findAll")
    public Result getType(){
        List<SysDictType>list=dictTypeService.list();
        return Result.success(list);
    }


    @ApiOperation(value = "获取订单品质类型")
    @RequestMapping(value = "/getOrderQuality", method = RequestMethod.GET)
    public Result<List<SysDictData>> queryOrderQuality() {
        return Result.success(dictDataService.queryOrderQuality());
    }

    @ApiOperation(value = "获取订单附件等级")
    @RequestMapping(value = "/getAttachmentType", method = RequestMethod.GET)
    public Result<List<SysDictData>> queryOrderAttachmentType() {
        return Result.success(dictDataService.queryOrderAttachmentType());
    }

    @ApiOperation(value = "获取订单风格类型")
    @RequestMapping(value = "/getOrderStyle", method = RequestMethod.GET)
    public Result<List<SysDictData>> queryOrderStyle() {
        System.out.println(dictDataService.queryOrderStyle());
        return Result.success(dictDataService.queryOrderStyle());
    }

    @ApiOperation(value = "获取订单制作小组")
    @RequestMapping(value = "/getOrderMakeTeam", method = RequestMethod.GET)
    public Result<List<SysDictData>> queryOrderMakeTeam() {
        return Result.success(dictDataService.queryOrderMakeTeam());
    }


}

